package com.demo.apparel.mapper.web;

import com.demo.apparel.entity.Admin;
import com.demo.apparel.entity.WxUser;
import com.demo.apparel.vo.web.AdminVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AdminMapper {

    @Select("SELECT id, phone, openid,password, is_super AS isSuper, created_time AS createdTime, updated_time AS updatedTime " +
            "FROM admin WHERE phone = #{phone}")
    @Results(id = "adminResultMap", value = {
            @Result(column = "id", property = "id", id = true),
            @Result(column = "phone", property = "phone"),
            @Result(column = "openid", property = "openid"),
            @Result(column = "password", property = "password"),
            @Result(column = "isSuper", property = "isSuper"),
            @Result(column = "createdTime", property = "createdTime"),
            @Result(column = "updatedTime", property = "updatedTime")
    })
    Admin selectByPhone(@Param("phone") String phone);





    /**
     *
     * @param admin
     * @return
     */
    @Insert("INSERT INTO admin (id, phone, openid,password, is_super, created_time, updated_time) " +
            "VALUES (#{id}, #{phone},#{openid} ,#{password}, #{isSuper}, #{createdTime}, #{updatedTime})")
    int insert(Admin admin);


    /**
     *
     * @param id
     * @return
     */
    @Select("SELECT * FROM admin WHERE id = #{id}")
    Admin selectById(@Param("id") String id);


    /**
     *
     * @param 更新密碼
     * @return
     */
    @Update("UPDATE admin SET password = #{password} WHERE id = #{id}")
    int updatePassword(Admin admin);

    /**
     *
     * @return
     */
    @Select("SELECT * FROM admin")
    List<Admin> getAllAdmins();

    @Delete("DELETE FROM admin WHERE id = #{id}")
    void deleteById(@Param("id") String id);


    @Select("SELECT id, phone, openid, password, is_super AS isSuper, created_time AS createdTime, updated_time AS updatedTime " +
            "FROM admin WHERE phone = #{phone}")
    Admin selectByPhones(@Param("phone") String phone);

    @Select("SELECT id, phone, openid, password, is_super AS isSuper, created_time AS createdTime, updated_time AS updatedTime " +
            "FROM admin WHERE id = #{id}")
    Admin selectByIds(@Param("id") String id);

    // AdminMapper.java
    Admin selectByOpenid(String openid);

    int updateOpenid(@Param("adminId") String adminId, @Param("openid") String openid);


}
